﻿using System;
using Eneta.Portal.Forum.Core.Data;
using Eneta.Portal.Forum.Core.Domain.Collections;
using Eneta.Portal.Forum.Core.Domain.Entities;

namespace Eneta.Portal.Forum.Core.Domain.Repositories
{
    public class TopicRepository
    {
        // Fields
        private readonly TopicDao _dao = new TopicDao();

        // Methods
        public void Delete(Topic topic)
        {
            _dao.Delete(topic);
        }

        public TopicCollection FindByDate(DateTime dateCriteria)
        {
            return _dao.FindByDate(dateCriteria);
        }

        public TopicCollection FindByForumId(int id)
        {
            return _dao.FindByForumId(id);
        }

        public TopicCollection FindInactive()
        {
            return _dao.FindInactive();
        }

        public TopicCollection GetAll()
        {
            return _dao.GetAll();
        }

        public Topic GetById(int id)
        {
            return _dao.GetById(id);
        }

        public void IncreasePostCount(int id)
        {
            var byId = GetById(id);
            byId.NumPosts++;
            Save(byId);
        }

        public void IncreaseViewCount(int id)
        {
            var byId = GetById(id);
            byId.Views++;
            Save(byId);
        }

        public int Save(Topic topic)
        {
            return _dao.Save(topic);
        }
    }
}
